package com.usian;

import com.sun.tools.attach.*;

import java.io.IOException;
import java.util.List;

public class AgentApp {
    public static void main(String[] args) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException {
        System.out.println("main running...");

        //获取当前系统中所有 运行中的 虚拟机
        List<VirtualMachineDescriptor> list = VirtualMachine.list();
        for (VirtualMachineDescriptor vm : list) {
            if (vm.displayName().endsWith("com.usian.AgentApp")) {
                VirtualMachine virtualMachine = VirtualMachine.attach(vm.id());
                virtualMachine.loadAgent("D:\\2111A\\hello2\\agentdemo\\target\\agentdemo.jar");
                virtualMachine.detach();
            }
        }
    }
}
